using System;
using System.Collections.Generic;
using System.Text;

namespace cb0tServer
{
    partial class ServerCore
    {
        private bool OnPMFilter(UserObject userobj, String text)
        {
            if (userobj.admin || userobj.host) return true;

            String str = Helpers.StripColors(text);
            FilterItem[] items = PMFilters.GetFilters();

            if (items == null) return true;

            foreach (FilterItem filter in items)
            {
                if (str.ToUpper().IndexOf(filter.trigger.ToUpper()) > -1)
                {
                    switch (filter.type)
                    {
                        case "kill":
                            UserPool.Broadcast(ServerOutboundPackets.AnnoucePacket(StringTemplate.GetString(47).Replace("+n", userobj.name)));
                            userobj.Disconnect();
                            this.OnPart(userobj);
                            Stats.UsersParted++;
                            Stats.KickedUsers++;
                            AdminLog.WriteLine(userobj.name + " was kicked for typing in pm " + filter.trigger);
                            return false;

                        case "ban":
                            UserPool.Broadcast(ServerOutboundPackets.AnnoucePacket(StringTemplate.GetString(48).Replace("+n", userobj.name)));
                            this.banstats.Add(userobj.name + " [" + userobj.physical_ip.ToString() + "] was banned by the PM filter");
                            Bans.AddBan(userobj);
                            userobj.Disconnect();
                            this.OnPart(userobj);
                            Stats.UsersParted++;
                            Stats.BannedUsers++;
                            Stats.KickedUsers++;
                            AdminLog.WriteLine(userobj.name + " was banned for typing in pm " + filter.trigger);
                            return false;

                        case "censor":
                            return false;
                    }
                }
            }

            return true;
        }
    }
}
